from common.base import Base, By, open_browser, sleep
import random

sj_account = 'buyer2503'+str(random.randint(000000,999999))

class BuyerRegPage(Base):
    _username_loc = (By.NAME, 'username')  # 用户名输入框
    _password_loc = (By.NAME, 'password')  # 密码输入框
    _repassword_loc = (By.NAME, 'repassword')  # 重复密码输入框
    _captcha_loc = (By.NAME, 'captcha')  # 验证码输入框
    _submit_reg_loc = (By.CLASS_NAME, 'submit_reg')  # 注册按钮
    _ret_status_loc = (By.CLASS_NAME, 'f14')  # 注册成功，提示词元素


    def input_username(self,username):
        self.send_keys(BuyerRegPage._username_loc,username)

    def input_password(self,password):
        self.send_keys(BuyerRegPage._password_loc,password)

    def input_repassword(self,repassword):
        self.send_keys(BuyerRegPage._repassword_loc,repassword)

    def input_captcha(self,captcha):
        self.send_keys(BuyerRegPage._captcha_loc,captcha)

    def click_reg(self):
        self.click(BuyerRegPage._submit_reg_loc)

    def is_sucess_reg(self,txt):
        text = self.get_element_text(BuyerRegPage._ret_status_loc)
        if text == txt:
            return True
        else:
            return False


if __name__ == '__main__':
    reg = BuyerRegPage(open_browser())
    reg.get_url('http://172.16.0.205/shop/index.php?controller=simple&action=reg')
    reg.input_username(sj_account)
    sleep(2)
    reg.input_password(sj_account)
    sleep(2)
    reg.input_repassword(sj_account)
    sleep(2)
    reg.input_captcha('55555')
    reg.click_reg()
    sleep(2)
    reg.driver.quit()